Q:
How do I detect if Macsbug is installed?
A:
To detect if Macsbug is loaded, or if any debugger is loaded, you
need to look at some low memory variables as documented in the "Macsbug
Reference & Debugging Guide", page 412. If you are running on a machine
which has a 32 bit capable Memory Manager, debugger flags are at low
memory location $BFF . If you are running on an older machine which only
contained a 24 bit capable Memory Manager, the debugger flags are at low
memory location $120. Note that the documentation is slightly
obscure - you check if the machine is capable of 32-bit mode, not if
you are running in 32 bit mode.
Think Reference 2.0.1 has a statement in its sample code which states:
ADDENDUM:
The above information seems to be incorrect in the
reference manual. I have found through testing etc. that in both
modes, the Flag Byte appears at location 0xBFF . The code reflects
these findings.
|
This is because they confused running in 24 bit mode, running in 32
bit mode, and the ability to run in 32 bit mode. It is the latter
ability which you must test to determine the location of the debugger
flags.
#include <Gestalt.h>
/* the 2 low memory locations you might need */
#define MacJmpByte (char *) 0x120 /* Macsbug flag on old machines */
#define MacJmpFlag (char *) 0xBFF /* MacsBug flag [byte] */
#define DebuggerInstalled 5
Boolean DebuggerIsPresent()
{
long addressingMode;
short debugFlags;
Gestalt(gestaltAddressingModeAttr, &addressingMode);
if (addressingMode & (1 << gestalt32BitCapable))
debugFlags = *MacJmpFlag;
else
debugFlags = *MacJmpByte;
return (debugFlags & (1 << DebuggerInstalled));
}
|
|